from rest_framework.viewsets import ReadOnlyModelViewSet
from rest_framework_extensions.cache.mixins import CacheResponseMixin

from . import serializers
from .models import Area
class AreaInfoView(CacheResponseMixin,ReadOnlyModelViewSet):
    # serializer_class = serializers.AreaInfoSerializer
    # queryset = Area.objects.filter(parent=None)
    pagination_class = None #关闭分页
    def get_serializer_class(self):
        if self.action == "list":
            return serializers.AreaInfoSerializer
        else:
            return serializers.AreaSubsInfoSerializer

    def get_queryset(self):
        if self.action == "list":
            return Area.objects.filter(parent=None)
        else:
            return Area.objects.all()